#ifndef ITEMFLAG_H
#define ITEMFLAG_H

#include <QMetaEnum>
#include "config/ConfigItem.h"


class ItemFlag : public ConfigItem {
    Q_OBJECT
public:
    QSet<int> get()
    {
        return m_data;
    }
    QMetaEnum getMetaEnum()
    {
        return m_enum;
    }
    void setFlag(const int &value, bool on=true)
    {
        if (on)
        {
            m_data.insert(value);
        }
        else
        {
            m_data.remove(value);
        }
        emit itemEdited();
    }
    void clearFlag()
    {
        m_data.clear();
        emit itemEdited();
    }

    bool testFlag(const int &value)
    {
        return m_data.contains(value);
    }
    void  setMetaEnum(const QMetaEnum &e)
    {
        m_enum = e;
    }
protected:
    QWidget *createWidget(WidgetStyle s) override;
    void update(QWidget *widget, UpdateOption option) override;
    void writeToData(QDataStream &stream) const override;
    void readFromData(QDataStream &stream) override;

private:
    QSet<int> m_data;
    QMetaEnum m_enum;
};

#endif // ITEMFLAG_H
